package com.tongtong.stsuserapi.controller;

import com.tongtong.stscommon.message.STSMessage;
import com.tongtong.stscommon.proxy.annotation.AutoGetId;
import com.tongtong.stsuserapi.service.base.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 购物车控制器
 */
@Api(tags="购物车接口")
@RestController
@RequestMapping("/sts/user/shoppingcart")
public class ShoppingCartController {

	@Autowired
	ShoppingCartService shoppingCartService;

	@ApiOperation("在购车中添加商品")
	@ApiImplicitParam(name = "userid", value = "该参数从token中自动获取，无需传入")
	@PostMapping
	@AutoGetId
	public STSMessage addItem(Long userid, Long itemId, Integer quantity) {
		return shoppingCartService.addItem(userid,itemId,quantity);
	}

	@ApiOperation("在购物车中删除商品")
	@ApiImplicitParam(name = "userid", value = "该参数从token中自动获取，无需传入")
	@DeleteMapping
	@AutoGetId
	public STSMessage deleteItem(Long userid, Long cartId) {
		return shoppingCartService.deleteItem(userid, cartId);
	}

	@ApiOperation("修改购物车中的商品数量")
	@ApiImplicitParam(name = "userid", value = "该参数从token中自动获取，无需传入")
	@PatchMapping
	@AutoGetId
	public STSMessage updateItem(Long userid, Long cartId, Integer quantity) {
		return shoppingCartService.updateItem(userid,cartId,quantity);
	}

	@ApiOperation("获取购物车中的商品列表")
	@ApiImplicitParam(name = "userid", value = "该参数从token中自动获取，无需传入")
	@GetMapping
	@AutoGetId
	public STSMessage getItems(Long userid, Integer page, Integer pageSize) {
		return shoppingCartService.getItems(userid,page,pageSize);
	}

}
